<?php

require_once("config.php");

$apiClient = new KewegoClient();

//set the application token from the application key
if ($apiClient->setAppToken($application_key)) {}
else die( "<hr />Error: can not set appToken, invalid application key<hr />");

//debug: echo '<hr />appToken : '.$apiClient->returnAppToken();

//set video id
if (isset($_GET['sig'])) $sig = $_GET['sig'];
else $sig = "iLyROoaftYea";

/* get video data */
$apiClient->Call($apiServer."video/getDetails/?sig=$sig");

//debug:
//print_r($apiClient->getResponse());

$xml = new SimpleXMLElement($apiClient->getResponse());
//debug: print_r($xml); exit();

//set a variable for each attribute of the video
$vars = array("title", "description", "author", "views", "duration", "rate", "publication_date", "language", "country", "postal_code", "access", "comments", "videoblog_link");
foreach($vars as $var)
{
	$$var = (String) $xml->message->$var;
	//echo $var."=".$$var."<br />";
}

//set an array $keywords with the keywords of the video
$keywords = array();
foreach($xml->message->keywords->keyword as $keyword)
{
	$keywords[] = (String) $keyword;
}
//print_r($keywords);

//set an array $categories with the categories of the video
$categories = array();
foreach($xml->message->categories->category as $category)
{
	$categories[] = (String) $category;
}
//print_r($categories);


//********
// Get Embed Code
//********

$params	= array();
$params['sig'] 				= $sig;
$params['player_key']		= '0f932efcc6b9';
$params['skin_key']			= '';
$params['language_code']	= 'fr';
$params['version']			= '9';
$params['autostart']		= true;

$apiClient->Call($apiServer."video/getPlayerCode/", $params);
$xml = new SimpleXMLElement($apiClient->getResponse());

$playerCode = (String) $xml->message->blog;

/* display player page */
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Video > <?php echo $title ?></title>
<style>

</style>
</head>
<body>
<?php include_once("menu.php"); ?>
	<h1>Video > <?php echo $title ?></h1>
	<?php echo $playerCode; ?>
	<br /><br /><b>Description</b>
	<br /><?php echo $description; ?>
	<br /><br /><b>Vues : </b><?php echo $views; ?>
</body></html>